/*
 * CS_DUNGEON_CLEAR.cpp
 *
 *  Created on: 2013. 10. 18.
 *      Author: jjaehuny
 */


#include "../../Command.h"

#include "../../User.h"
#include "../../NLogic/Space.h"
#include "../../NLogic/Score.h"
#include "../../NLogic/Battle.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_DUNGEON_CLEAR(User * pUser, ::Network::Packet * pPacket)
{
	/*
	 *
	 CS_DUNGEON_CLEAR					0x0832
	{
		u8	u8DungeonIndex;
		u8	u8DungeonClearState;		// 1 : clear, 0 : not clear, 2: played
	}

	SC_DUNGEON_CLEAR					0x0833
	{
		s16	ack;				/// 1:완료 ,  -1 실패
	}
	 */

	PREPARE_PACKET;

	if (pUser->GetSpace() == NULL)
	{
		DEBUGLOG("");
		return;
	}

	uint8_t u8DungeonIndex = 0;
	uint8_t u8DungeonClearState = 0;
	* pPacket >> u8DungeonIndex >> u8DungeonClearState;

	if (0 > u8DungeonIndex || u8DungeonIndex >= MAX_DUNGEON_COUNT)
	{
		DEBUGLOG("CS_DUNGEON_CLEAR 0 > u8DungeonIndex || u8DungeonIndex > 150 : %d", u8DungeonIndex);
		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		* pAck << static_cast<int16_t>(-1);
		pAck->MakePacket(CMD_SC_DUNGEON_CLEAR);
		pUser->Send(pAck);
		return;
	}

	if (0 > u8DungeonClearState || u8DungeonClearState > 2)
	{
		DEBUGLOG("0 > u8DungeonClearState || u8DungeonClearState > 2 : %d", u8DungeonClearState);
		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		* pAck << static_cast<int16_t>(-1);
		pAck->MakePacket(CMD_SC_DUNGEON_CLEAR);
		pUser->Send(pAck);

		return;
	}

	User::DUNGEON_CREAR_INFO & clsDungeonClearInfo = pUser->GetDungeonClearInfo();
	if (false == clsDungeonClearInfo.SetValue(u8DungeonIndex, u8DungeonClearState))
	{
		DEBUGLOG("ERROR %s pUser->clsDungeonClearInfo().SetValue index %d GID : %d", __FUNCTION__, u8DungeonIndex, pUser->GetUserSeq());
	}

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	* pAck << static_cast<int16_t>(ACK_OK);
	pAck->MakePacket(CMD_SC_DUNGEON_CLEAR);
	pUser->Send(pAck);
}

} /*NCommand*/ } /*ProjectZ*/







